package com.gs.SynPatrolRep.util;

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.widget.Toast;

import com.gs.SynPatrolRep.MyApplication;

public class BluetoothUtil {
    public static BluetoothAdapter mBluetoothAdapter;

    public BluetoothUtil(Activity activity) {
        if (mBluetoothAdapter == null) {
            init(activity);
        }
    }

    private void init(Activity activity) {
        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        if (mBluetoothAdapter == null) {
            Toast.makeText(MyApplication.getContext(),"設備不支持藍牙",Toast.LENGTH_LONG).show();
            return;
        }
        if (!mBluetoothAdapter.isEnabled()) {
            Toast.makeText(MyApplication.getContext(),"请打开蓝牙",Toast.LENGTH_LONG).show();
            openBluetooth(activity);
            return;
        }
    }

    /**
     * 打开蓝牙
     * @param activity
     */
    private void openBluetooth(Activity activity) {
        Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        activity.startActivityForResult(intent, 800);
    }
}
